package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjInfoBean;
import com.koron.css2.newProjectCenter.bean.PjSettlement;
import com.koron.css2.newProjectCenter.bean.query.PjSettlementQuery;
import com.koron.css2.newProjectCenter.mapper.PjInfoMapper;
import com.koron.css2.newProjectCenter.mapper.PjSettlementMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 工程报装-编制结算单条数据详情
 */
public class PjSettlemetSingle implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjSettlementQuery pjSettlementQuery = JsonUtils.objectToPojo(req.getData(),PjSettlementQuery.class);

            PjSettlementMapper pjSettlementMapper = factory.getMapper(PjSettlementMapper.class);
            PjInfoMapper pjInfoMapper = factory.getMapper(PjInfoMapper.class);

            // 1. 查询数据
            PjSettlement pjSettlement = pjSettlementMapper.getSingle(pjSettlementQuery);
            // 2. consultBillNo,consultName,disposableChargeFlag,budgetMoney
            PjInfoBean pjInfoBean = pjInfoMapper.selectById(pjSettlement.getConsultId());
            pjSettlement.setConsultBillNo(pjInfoBean.getBillNo());
            pjSettlement.setConsultName(pjInfoBean.getPjName());
            pjSettlement.setDisposableChargeFlag(pjInfoBean.getDisposableChargeFlag());
            pjSettlement.setBudgetMoney(pjInfoBean.getBudgetMoney());
            // 3. 返回数据
            MessageBean<PjSettlement> messageBean = MessageBean.create
                    (Constant.MESSAGE_INT_SUCCESS,"编制结算单条数据详情查询成功", PjSettlement.class);
            messageBean.setData(pjSettlement);
            return messageBean;
        } catch (Exception e) {
            logger.error("编制结算单条数据详情查询失败",e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL,"编制结算单条数据详情查询失败",null);
        }
    }
}
